/*
 * @Descripttion: 
 * @version: 
 * @Author: turingchang
 * @Date: 2020-08-28 14:32:50
 * @LastEditors: turingchang
 * @LastEditTime: 2020-12-23 11:20:59
 */

'use strict';
const BaseController = require('../base/base');
const schedule = require('node-schedule');

class HomeController extends BaseController {
  async test() {
    var data = {
      name: 'uuuuuuu',
      pwd: 'adsfafafasd',
      gg: null,
      jj: undefined,
      h: {},
      ro: {
        xxx: 0,
        ccc: null
      }
    };
    this.ctx.outSuccess('', data);
  }

  async schedule() {
    const ctx =this.ctx;
    var rule = new schedule.RecurrenceRule();
    var times = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56];
    rule.second = times;
    var a =await schedule.scheduleJob('test01',rule, function () {
      console.log(101,ctx.app.utils.time.moment().format("YYYY-MM-DD HH:mm:ss"));
      var time = a.nextInvocation();
      var convertedTime = new Date(time);
      console.log(102,ctx.app.utils.time.moment(convertedTime).format("YYYY-MM-DD HH:mm:ss"));     
    });    
    console.log(100,a);
    
    for (let i in schedule.scheduledJobs) {
      console.error("正确开启的定时任务名称："+i);
    }

    var s = ctx.app.utils.generator.uid();
    this.ctx.outSuccess(s);
  }

  async list() {
    const list = await this.ctx.model.Job.Job.findAll();
    console.log(222,JSON.stringify(list));
    this.ctx.outSuccess('',list);
  }
  

}

module.exports = HomeController;